package com.jxt.myjxtmanager.ui.activity;

import android.content.ClipboardManager;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jxt.myjxtmanager.BaseActivity;
import com.jxt.myjxtmanager.R;
import com.jxt.myjxtmanager.utils.Config;
import com.jxt.myjxtmanager.utils.PackageUtils;
import com.jxt.myjxtmanager.utils.SystemInfo;

/**
 * 应用程序关于界面
 *
 * @author lkk
 */
public class AboutActivity extends BaseActivity {

    /**
     * 版本号
     */
    TextView tvProgramViewson;
    /**
     * logo
     */
    ImageView ivLogo;
    /**
     * 客服电话
     */
    View tvSerViceTel;
    /**
     * 客服微信
     */
    View ll_server_weixin;

    private TextView tv_server_weixin_show;

    @Override
    protected int getLayoutId() {
        // TODO Auto-generated method stub
        return R.layout.activity_about;
    }

    @Override
    protected void initView() {
        setToolbarTitle("关于我们");
        setToolbarNavigationIcon(R.drawable.ic_left_return);
        tvProgramViewson = (TextView) findViewById(R.id.tv_proram_version);
        ivLogo = (ImageView) findViewById(R.id.iv_programe_logo);
        tvSerViceTel = findViewById(R.id.ll_server_tel);
        ll_server_weixin = findViewById(R.id.ll_server_weixin);
        tv_server_weixin_show = (TextView) findViewById(R.id.tv_server_weixin_show);
        tvSerViceTel.setOnClickListener(this);
        ll_server_weixin.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        String version = PackageUtils.getAppVersion(this);
        tvProgramViewson.setText(getString(R.string.program_version, version));
    }

    @Override
    protected void onClickView(int key) {
        switch (key) {
            case R.id.ll_server_tel:
                // 用intent启动拨打电话
                SystemInfo.callPhone(this, Config.SERVER_TEL);
                break;
            case R.id.ll_server_weixin:
                copy(tv_server_weixin_show.getText().toString().trim(), this);
                break;
            default:
                break;
        }
    }

    @Override
    public void onClickLeftMenu() {
        onBackPressed();
    }

    /**
     * 拷贝文字到剪贴板
     */
    public void copy(String text, Context context) {
        // 得到剪贴板管理器
        ClipboardManager cmb = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        cmb.setText(text.trim());
        Toast.makeText(this, "已复制到剪切板", Toast.LENGTH_SHORT).show();
    }
}
